﻿using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class CombatantView : MonoBehaviour
{


    public int MaxHealth { get; set; }
    public int CurrentHealth { get; set; }
    public int defence { get; set; }
    [SerializeField] protected HealthTextBar healthTextBar;

    void Start()
    {
        if (healthTextBar != null)
        {
            healthTextBar.SetHealth(CurrentHealth, defence, MaxHealth);
        }
    }


    public virtual void Damage(int Amount)
    {
        // 护盾抵挡的伤害量，不能超过当前护盾值
        int shieldAbsorb = Mathf.Min(defence, Amount);

        defence -= shieldAbsorb;
        int remainingDamage = Amount - shieldAbsorb;

        CurrentHealth -= remainingDamage;
        CurrentHealth = Mathf.Max(CurrentHealth, 0);

        healthTextBar.SetHealth(CurrentHealth, defence, MaxHealth);
        transform.DOShakePosition(0.25f, 0.25f);
    }
    public virtual void Heal(int Amount)
    {
        CurrentHealth += Amount;
        if (CurrentHealth >= MaxHealth) CurrentHealth = MaxHealth;
        healthTextBar.SetHealth(CurrentHealth, defence, MaxHealth);
    }
    public virtual void Defence(int defenceAmount)
    {
        // Debug.Log($"CVDF {defenceAmount}");
        defence += defenceAmount;
        healthTextBar.SetHealth(CurrentHealth, defence, MaxHealth);
    }

}

